package study.javaee.practice.config;

import org.aspectj.weaver.StandardAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import study.javaee.practice.property.EmailProperty;

import javax.annotation.Resource;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

@Configuration
public class MailConfig {
    @Autowired
    EmailProperty emailProperty;
    @Bean
    JavaMailSenderImpl mailSender(){
        JavaMailSenderImpl  mailSender = new JavaMailSenderImpl();
        mailSender.setHost(emailProperty.getEmailHost());
        mailSender.setProtocol("smtp");
        mailSender.setPassword(emailProperty.getPassword());
        mailSender.setUsername(emailProperty.getSender());
        mailSender.setDefaultEncoding(StandardCharsets.UTF_8.name());
        return mailSender;
    }

}
